import java.util.Stack;

public class Stack_paixu {
    class Solution {
        public boolean validateStackSequences(int[] pushed, int[] popped) {
            Stack<Integer> pushh =  new Stack<>();
            int j =0;
            for(int i=0; i<pushed.length; i++){
                pushh.push(pushed[i]);
                while(j<pushed.length&& !pushh.empty()&&popped[j]==pushh.peek() ){
                    pushh.pop();
                    j++;
                }
            }
            return pushh.empty();
        }
    }
}
